package com.rc.evcharger.service.order;

import com.github.dozermapper.core.Mapper;
import com.rc.evcharger.common.constant.SocketConstant;
import com.rc.evcharger.common.constant.WebConstant;
import com.rc.evcharger.common.enums.HlhtOrderStatusEnum;
import com.rc.evcharger.mapper.elec.ElecGunMapper;
import com.rc.evcharger.mapper.elec.ElecPileMapper;
import com.rc.evcharger.mapper.hlht.HlhtOrderInfoMapper;
import com.rc.evcharger.mapper.member.MemberInfoMapper;
import com.rc.evcharger.mapper.order.OrderInfoMapper;
import com.rc.evcharger.mapper.rc.RcMemberFlagMapper;
import com.rc.evcharger.model.elec.*;
import com.rc.evcharger.model.hlht.HlhtOrderInfo;
import com.rc.evcharger.model.hlhtsk.HlhtskTenant;
import com.rc.evcharger.model.member.MemberInfo;
import com.rc.evcharger.model.order.*;
import com.rc.evcharger.model.rc.RcMemberFlag;
import com.rc.evcharger.redis.RedChargeDataService;
import com.rc.evcharger.redis.RedOrderService;
import com.rc.evcharger.service.car.TenantCarNumberService;
import com.rc.evcharger.service.elec.ElecStationPriceService;
import com.rc.evcharger.service.elec.ElecStationService;
import com.rc.evcharger.service.hlht.HlhtTenantOpenPriceService;
import com.rc.evcharger.service.hlhtsk.HlhtskTenantService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

/**
 * Created by sven on 2019/09/23.
 */
@Service
public class OrderInfoServiceImpl implements OrderInfoService {
    private static Logger logger = LogManager.getLogger(OrderInfoServiceImpl.class);

    @Autowired
    private OrderInfoMapper orderInfoMapper;

    @Autowired
    private MemberInfoMapper memberInfoMapper;

    @Autowired
    private ElecGunMapper elecGunMapper;

    @Autowired
    private ElecPileMapper elecPileMapper;

    @Autowired
    private ElecStationPriceService elecStationPriceService;

    @Autowired
    private ElecStationService elecStationService;

    @Autowired
    private RedOrderService redOrderService;

    @Autowired
    private OrderCommentService orderCommentService;

    @Autowired
    private TenantCarNumberService tenantCarNumberService;

    @Autowired
    private HlhtTenantOpenPriceService tlhtTenantOpenPriceService;

    @Autowired
    private RcMemberFlagMapper rcMemberFlagMapper;

    @Autowired
    private HlhtskTenantService hlhtskTenantService;

    @Autowired
    private HlhtOrderInfoMapper hlhtOrderInfoMapper;

    @Autowired
    private RedChargeDataService redChargeDataService;

    @Autowired
    private Mapper dozerMapper;

    @Override
    public OrderInfoMapper getMapper() {
        return orderInfoMapper;
    }

    @Override
    public OrderInfo addOrder(String rtua, String gunNum, String orderNum) {
        ElecPileExample pileExample = new ElecPileExample();
        pileExample.createCriteria().andPileRtuaEqualTo(rtua);
        List<ElecPile> piles = elecPileMapper.selectByExample(pileExample);

        ElecPile pile = piles.get(0);
        ElecGunExample gunExample = new ElecGunExample();
        gunExample.createCriteria().andElecPileIdEqualTo(pile.getElecPileId());
        List<ElecGun> guns = elecGunMapper.selectByExample(gunExample);

        ElecGun gun = null;
        for (ElecGun g : guns) {
            if (gunNum.endsWith(g.getGunNum())) {
                gun = g;
                break;
            }
        }
        if (gun == null) {
            gun = guns.get(0);
        }

        //gun.setStatus(SocketConstant.GUN_USE);
        //elecGunMapper.updateByPrimaryKeySelective(gun);

        ElecGun upateElecGun = new ElecGun();
        upateElecGun.setElecGunId(gun.getElecGunId());
        upateElecGun.setStatus(SocketConstant.GUN_USE);
        elecGunMapper.updateByPrimaryKeySelective(upateElecGun);

        //查找外部订单号和钱包类型
        OrderComment orderComment = orderCommentService.selectByOrderNum(orderNum);

        if (orderComment == null) {
            logger.error("orderComment预订单中无此订单，{}", orderNum);
            return null;
        }
        OrderInfo orderInfo = this.selectByOrderNum(orderNum);
        if (orderInfo != null) {
            logger.error("addOrder订单已存在，订单号:{}", orderNum);
            return null;
        }

        Long memberId = orderComment.getMemberId();
        MemberInfo memberInfo = memberInfoMapper.selectByPrimaryKey(memberId);


        //单冲会员设置为使用中
        if ((SocketConstant.CON0 + "").equals(memberInfo.getChargeType())) {
            memberInfo.setChargeStatus(SocketConstant.ELEC_USE + "");
            memberInfoMapper.updateByPrimaryKeySelective(memberInfo);
        }

        //创建订单
        OrderInfo order = new OrderInfo();
        order.setElecPileId(pile.getElecPileId());
        order.setElecStationId(pile.getElecStationId());
        order.setOperatorId(pile.getOperatorId());
        order.setMemberId(memberId);
        order.setStatus(SocketConstant.ORDER_STATUS_USEING);
        order.setElecGunId(gun.getElecGunId());
        order.setTotalMoney(BigDecimal.ZERO);
        order.setSoc(BigDecimal.ZERO);
        order.setTenantCode(orderComment.getTenantCode());
        order.setHlhtTenantCode(orderComment.getHlhtTenantCode());

        ElecStation elecStation = elecStationService.selectByPrimaryKey(pile.getElecStationId());
        order.setTenantOperatorCode(elecStation.getTenantOperatorCode());
        order.setOperatorId(elecStation.getOperatorId());

        order.setOutOrderNum(orderComment.getOutOrderNum());
        order.setAccountType(orderComment.getAccountType());
        order.setOrderSource(orderComment.getOrderSource());
        order.setStartType(orderComment.getStartType());
        order.setTicketUsingType(orderComment.getTicketUsingType());
        order.setMemberTicketIds(orderComment.getMemberTicketIds());
        order.setIsUseGiveAmount(orderComment.getIsUseGiveAmount());

        order.setCarVin(orderComment.getCarVin());     //添加vin码
        order.setDriverId(orderComment.getDriverId());  //司机ID
        order.setCarNum(orderComment.getCarNum());  //车牌号

        order.setCreatedTime(new Date());
        order.setStartTime(new Date());
        order.setOrderNum(orderNum);
        order.setElecPrices(getPrices(pile, SocketConstant.CON1 + ""));  //基本电费列表
        order.setServicePrices(getPrices(pile, SocketConstant.CON2 + "")); //服务费列表
        order.setHlhtOrderType(orderComment.getHlhtOrderType());

        order.setChargingPolicy(orderComment.getChargingPolicy()); //充电策略与参数
        order.setChargingPolicyParm(orderComment.getChargingPolicyParm());

        //添加车牌号
        if (orderComment.getCarNum() == null) {
            //加入默认车牌号
            String carNum = tenantCarNumberService.findCarNumByMemberId(memberInfo.getMemberId(), memberInfo.getTenantCode());
            order.setCarNum(carNum);

            //VIN码充电，则覆盖默认车牌号
            String carNumber = tenantCarNumberService.findCarNumberByVin(orderComment.getCarVin(), order.getTenantCode(), SocketConstant.CON0);
            if (carNumber != null) {
                order.setCarNum(carNumber);
            }
        } else {
            order.setCarNum(orderComment.getCarNum());
        }


        //反向互联互通新增调整后单价服务费
        if ("3".equals(memberInfo.getMemberType())) {

            //互联互通订单类型以tenant_code为基准,0为自主订单 1反向对接订单 2正向对接订单, 默认0
            if (!"3".equals(order.getHlhtOrderType())) {
                order.setHlhtOrderType(SocketConstant.STR_CON1);
            }

            String adjustServicePrices = tlhtTenantOpenPriceService.selectHlhtAdjustServicePrices(order, SocketConstant.STR_CON0);
            order.setAdjustServicePrices(adjustServicePrices);  //系数值设置
            String selectHlhtAdjustServiceFactPrices = tlhtTenantOpenPriceService.selectHlhtAdjustServicePrices(order, SocketConstant.STR_CON1);
            order.setAdjustServicePrices(selectHlhtAdjustServiceFactPrices);  //系数值+服务费单机和 设置
        }


        RcMemberFlag rcMemberFlag = rcMemberFlagMapper.selectByPrimaryKey(memberInfo.getMemberId());
        if (!SocketConstant.STR_CON0.equals(order.getAccountType())) {
//            order.setEnterpriseId(memberInfo.getBelongEnterpriseId());  //所属企业ID
            order.setEnterpriseId(rcMemberFlag.getEnterpriseId());  //所属企业ID
        }

        orderInfoMapper.insertSelective(order);


        //保存内部外联订单的反向订单
        if ("3".equals(order.getHlhtOrderType())) {
            HlhtOrderInfo updateHlhtOrderInfo = dozerMapper.map(order, HlhtOrderInfo.class);

            HlhtskTenant hlhtskTenant0 = hlhtskTenantService.selectHlhtTenantCode(order.getTenantCode(), order.getHlhtTenantCode());
            updateHlhtOrderInfo.setMemberId(hlhtskTenant0.getHlhtMemberId());//代表按瑞晨互联用户

            updateHlhtOrderInfo.setHlhtOrderType("1"); //反向订单
            //无优惠
            updateHlhtOrderInfo.setDiscountAmount(BigDecimal.ZERO);
            updateHlhtOrderInfo.setDiscountServiceAmount(BigDecimal.ZERO);
            updateHlhtOrderInfo.setPayAmount(updateHlhtOrderInfo.getTotalMoney());

            //调整价
            updateHlhtOrderInfo.setServiceAdjustDiscAmount(BigDecimal.ZERO);
            updateHlhtOrderInfo.setAdjustPayAmount(updateHlhtOrderInfo.getAdjustTotalMoney());

            hlhtOrderInfoMapper.insertSelective(updateHlhtOrderInfo);
        }

        logger.warn("用户手机号码:{}在枪编号:{}, 生成订单号:{}", memberInfo.getMobile(), gun.getGunNo(), order.getOrderNum());

        //同时将订单保存到redis缓存中
        redOrderService.addOrder(rtua, gunNum, order.getOrderNum(), order.getOrderNum());
        redChargeDataService.putOrderNum(rtua, gunNum, order.getOrderNum(), order.getOrderNum());
        //模糊查询order即可，无需过度
        //redOrderService.addOrder(rtua, gunNum, memberInfo.getMobile(), memberInfo.getMobile());

        return order;
    }

    @Override
    public void updateStatusByOrderInfo(Long orderId) {
        OrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);

        OrderInfo orderInfo1 = new OrderInfo();
        orderInfo1.setOrderId(orderId);
        orderInfo1.setStatus("5");

        orderInfoMapper.updateByPrimaryKeySelective(orderInfo1);
    }

    /**
     * //12位枪号 + 12位日期时间 + 4位随机数 28位
     *
     * @return
     */
    //@Override
    //public synchronized String addOrderNum(String epNo) {
    //StringBuffer orderNum = new StringBuffer(epNo);
    //orderNum.append(DateHelper.dataToString(new Date(), DateHelper.DATE_FORMAT_YYMMDDHHMMSS));
    //orderNum.append(String.format("%03d", (int) (Math.random() * 1000)));
    //logger.warn("枪:" + epNo + " 生产的订单号为:" + orderNum.toString());
    //
    //return orderNum.toString();
    //}

//    @Override
//    public void updateOrder(String orderNum, Integer stopReason) {
//        //OrderInfo order = orderInfoMapper.selectByOrderNum(orderNum);
//        OrderInfo order = selectByOrderNum(orderNum);
//
//        if (order.getStatus().equals(SocketConstant.CON2)) {
//            return;
//        }
//
//        MemberInfo memberInfo = memberInfoMapper.selectByPrimaryKey(order.getMemberId());
//
//        ElecGun gun = elecGunMapper.selectByPrimaryKey(order.getElecGunId());
//        ElecPile pile = elecPileMapper.selectByPrimaryKey(gun.getElecPileId());
//
//        try {
//            BigDecimal power = redChargeDataService.getPower(pile.getPileRtua(), gun.getGunNum(), memberInfo.getMobile());
//            BigDecimal baseAmount = redChargeDataService.getBaseAmount(pile.getPileRtua(), gun.getGunNum(), memberInfo.getMobile());
//            BigDecimal chargeAmount = redChargeDataService.getAmount(pile.getPileRtua(), gun.getGunNum(), memberInfo.getMobile());
//            BigDecimal serviceAmount = redChargeDataService.getServiceAmount(pile.getPileRtua(), gun.getGunNum(), memberInfo.getMobile());
//            BigDecimal soc = redChargeDataService.getSoc(pile.getPileRtua(), gun.getGunNum(), memberInfo.getMobile());
//            String stopMode = redChargeDataService.getStopMode(pile.getPileRtua(), gun.getGunNum(), memberInfo.getMobile());
//            String pileStopMode = redChargeDataService.getPileStopMode(pile.getPileRtua(), gun.getGunNum(), memberInfo.getMobile());
//
//            //todo 上线前必须关闭
////            BigDecimal power = BigDecimal.ZERO;
////            BigDecimal baseAmount = BigDecimal.ZERO;
////            BigDecimal chargeAmount = BigDecimal.ZERO;
////            BigDecimal serviceAmount = BigDecimal.ZERO;
////            BigDecimal soc = BigDecimal.ZERO;
//
//            logger.warn("后台结算订单id:" + orderNum + ",桩地址：" + pile.getPileRtua() + "orderservice实例地址：" + this.toString());
//
//            saveOrderRecord(order, pile, chargeAmount, baseAmount, serviceAmount, soc, power);
//
//            //优惠、结算
//            Date date = new Date();
//            updateOrder(order, null, date, baseAmount, serviceAmount, soc, power);
//
//            /**判断停止原因**/
//            stopReason(stopMode, order);
//            //更新订单订单原因
//            OrderInfo newOrder = new OrderInfo();
//            newOrder.setOrderId(order.getOrderId());
//            newOrder.setStopReason(order.getStopReason());
//            if (StringUtil.isEmpty(pileStopMode)) {
//                newOrder.setPileStopReason(0);
//            } else {
//                Integer intCode = Integer.parseInt(pileStopMode, 16);
//                newOrder.setPileStopReason(intCode);
//            }
//            orderInfoMapper.updateByPrimaryKeySelective(newOrder);
//        } catch (Exception e) {
//            logger.error("结算出错:", e);
//        } finally {
////            gun.setUsingStatus(SocketConstant.CON0);
////            order.setOrderNum(DataUtil.PERMISSON[0] + order.getOrderNum().substring(2));
//            clear(pile.getPileRtua(), gun.getGunNum(), memberInfo.getMobile(), memberInfo.getMemberId());
//        }
//    }

    //@Override
    //public void updateOrder(String rtua, String gunNum) {
    //
    //}
    @Override
    public void updateOrderBySocOrVin(Long orderId, BigDecimal soc, String vin) {
        OrderInfo order = orderInfoMapper.selectByPrimaryKey(orderId);

        if (soc.compareTo(BigDecimal.ZERO) > 0 &&
                (order.getBeginSoc() == null || order.getBeginSoc().compareTo(BigDecimal.ZERO) == 0)) {

            OrderInfo newOrderInfo = new OrderInfo();
            newOrderInfo.setOrderId(order.getOrderId());
            newOrderInfo.setBeginSoc(soc);

            //更新开始SOC
            orderInfoMapper.updateByPrimaryKeySelective(newOrderInfo);
        }
        if (!WebConstant.INVALID_VIN.equals(vin) && (order.getCarVin() == null || WebConstant.INVALID_VIN.equals(order.getCarVin()))) {

            OrderInfo newOrderInfo = new OrderInfo();
            newOrderInfo.setOrderId(order.getOrderId());
            newOrderInfo.setCarVin(vin);

            String carNumber = tenantCarNumberService.findCarNumberByVin(vin, order.getTenantCode(), SocketConstant.CON0);
            if (carNumber != null) {
                newOrderInfo.setCarNum(carNumber);
            }

            //更新VIN码
            orderInfoMapper.updateByPrimaryKeySelective(newOrderInfo);
        }
    }

    //private void updateOrder(OrderInfo order0, Date startTime, Date endTime, BigDecimal baseAmount, BigDecimal serviceAmount,
    //                         BigDecimal soc, BigDecimal power) throws Exception {
    //    if (order0.getSoc().intValue() > 0) {
    //        soc = order0.getSoc();
    //    }
    //    OrderInfo order = new OrderInfo(startTime, endTime, power, SocketConstant.ORDER_STATUS_USED, soc, order0.getHlhtOperatorId());
    //
    //    // 更新用户余额，解锁充电状态
    //    MemberInfo memberInfo = memberInfoMapper.selectByPrimaryKey(order0.getMemberId());
    //
    //    //会员状态改为0.充电
    //    memberInfo.setChargeStatus(SocketConstant.ELEC_NOT + "");
    //
    //    //将order复制到order0
    //    BeanUtil.setBeanByOtherBeanWithoutNull(order0, order);
    //
    //    //得到四舍五入后的服务费，基本电费，总价格 并赋值到order0中
    //    serviceAmount = serviceAmount.setScale(2, BigDecimal.ROUND_HALF_UP);
    //    baseAmount = baseAmount.setScale(2, BigDecimal.ROUND_HALF_UP);
    //    BigDecimal chargeAmount = baseAmount.add(serviceAmount);
    //    BigDecimal payAmount = chargeAmount;
    //
    //    //赋值到订单表中;
    //    order0.setTotalSeviceMoney(serviceAmount);
    //    order0.setDiscountServiceAmount(serviceAmount);
    //    order0.setTotalElecMoney(baseAmount);
    //    order0.setTotalMoney(chargeAmount);
    //    order0.setPayAmount(payAmount);
    //    order0.setDiscountAmount(BigDecimal.ZERO); //优惠金额设为0
    //    order0.setTotalPower(power);
    //
    //    //个人钱包服务费打折
    //    tenantDiscountMemberStationService.saleServiceAmountByOrder(order0);
    //
    //    //更新会员余额
    //    MemberAccount memberAccount = memberAccountMapper.selectByMemberId(memberInfo.getMemberId());
    //    BigDecimal account = memberAccount.getAccount().subtract(order0.getPayAmount());
    //    memberAccount.setAccount(account);
    //
    //    //添加余额记录
    //    MemberAccountRecord accountRecord = null;
    //    accountRecord = new MemberAccountRecord(memberInfo.getMemberId(), order0.getOrderNum(), order0.getPayAmount(),
    //            account, endTime, order0.getAccountType());
    //
    //    logger.warn("结算后 订单号={}, chargamout={}, basemount={}, servermount={},payAmount={},discountAmount={},power:{}"
    //            , order0.getOrderNum(), order0.getTotalMoney(), order0.getTotalElecMoney(), order0.getTotalSeviceMoney()
    //            , order0.getPayAmount(), order0.getDiscountServiceAmount(), order0.getTotalPower());
    //
    //    accountRecord.setTenantCode(memberInfo.getTenantCode());
    //
    //    memberAccountRecordMapper.insertSelective(accountRecord);
    //    memberAccountMapper.updateMemberAccountByMemberId(memberAccount);
    //    orderInfoMapper.updateByPrimaryKey(order0);
    //
    //    //更新用户状态
    //    MemberInfo updateMember = new MemberInfo();
    //    updateMember.setMemberId(memberInfo.getMemberId());
    //    updateMember.setChargeStatus(SocketConstant.ELEC_NOT + "");
    //    memberInfoMapper.updateByPrimaryKeySelective(updateMember);
    //}

    //@Override
    //public OrderInfo getByOrderNum(String orderNum) {
    //    OrderInfoExample orderExample = new OrderInfoExample();
    //    orderExample.createCriteria().andOrderNumEqualTo(orderNum);
    //
    //    List<OrderInfo> orders = orderInfoMapper.selectByExample(orderExample);
    //    if (!CollectionUtils.isEmpty(orders)) {
    //        return orders.get(0);
    //    }
    //    return null;
    //}

    @Override
    public Integer countElecOrder(MemberInfo memberInfo) {

        Calendar instance = Calendar.getInstance();
        instance.add(Calendar.HOUR_OF_DAY, -5);

        return orderInfoMapper.countElecOrder(memberInfo.getMemberId(), memberInfo.getTenantCode(), instance.getTime());
    }

    @Override
    public OrderInfo selectByOrderNum(String orderNum) {
        return orderInfoMapper.selectForceMasterOrderNum(orderNum);
        //return orderInfoMapper.selectByOrderNum(orderNum);
        //if (StringUtils.isEmpty(orderNum)) {
        //    return null;
        //}
        //OrderInfoExample orderExample = new OrderInfoExample();
        //orderExample.createCriteria().andOrderNumEqualTo(orderNum);
        //
        //List<OrderInfo> orders = orderInfoMapper.selectByExample(orderExample);
        //if (!CollectionUtils.isEmpty(orders)) {
        //    return orders.get(0);
        //}
    }

    @Override
    public OrderInfo selectNewOrderByMemberIdAndGunId(Long memberId, Long gunId) {
        return orderInfoMapper.selectNewOrderByMemberIdAndGunId(memberId, gunId);
    }

    @Override
    public OrderInfo selectNewOrderByMemberId(Long memberId) {
        return orderInfoMapper.selectNewOrderByMemberId(memberId);
    }

    @Override
    public OrderInfo selectByPileIdAndGunId(Long elecPileId, Long elecGunId) {
        return orderInfoMapper.selectByPileIdAndGunId(elecPileId, elecGunId);
    }

    @Override
    public List<OrderInfo> listDdByDateAndMemberId(String date, Long memberId) {
        return orderInfoMapper.listDdByDateAndMemberId(date, memberId);
    }

    @Override
    public List<OrderInfo> listExceptionOrderInfoKy() {
        return orderInfoMapper.listExceptionOrderInfoKy();
    }

    /**
     * 盛弘结算更新订单开始soc
     **/
    @Override
    public void updateBeginSocByOrderId(Long orderId, BigDecimal beginSoc) {
        OrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);

        OrderInfo newOrderinfo = new OrderInfo();
        newOrderinfo.setOrderId(orderInfo.getOrderId());
        newOrderinfo.setBeginSoc(beginSoc);

        orderInfoMapper.updateByPrimaryKeySelective(newOrderinfo);
        logger.info("更新盛弘订单的开始soc,对应订单ID：{}，开始soc:{}", orderId, beginSoc);
    }

    @Override
    public List<OrderInfo> listNotFinishedOrder(Date startTime, Date endTime) {
        return orderInfoMapper.listNotFinishedOrder(startTime, endTime);
    }

    //结算互联互通订单信息的状态
    @Override
    public int updateStatusByHlhtOrderInfo(Long orderId) {

        OrderInfo newOrderInfo = new OrderInfo();
        newOrderInfo.setOrderId(orderId);
        newOrderInfo.setStatus(HlhtOrderStatusEnum.HlhtOrderStatus2.getCode());
        newOrderInfo.setHlhtOrderStatus(HlhtOrderStatusEnum.HlhtOrderStatus4.getCode());

        orderInfoMapper.updateByPrimaryKeySelective(newOrderInfo);
        return 1;
    }

    @Override
    public OrderInfo selectLikeOrderNum(String orderNum) {
        return orderInfoMapper.selectLikeOrderNum(orderNum);
    }

    @Override
    public List<OrderInfo> queryExcetptionOrderInfo() {
        return orderInfoMapper.queryExcetptionOrderInfo();
    }

    @Override
    public int insertSelectiveBackOrderId(OrderInfo orderInfo) {
        return orderInfoMapper.insertSelectiveBackOrderId(orderInfo);
    }


    /**
     * 获取电费列表
     *
     * @param pile
     * @param priceType 1.基本电费，2服务费
     * @return
     */
    private String getPrices(ElecPile pile, String priceType) {
        List<ElecStationPrice> list = elecStationPriceService.listByStationId(pile.getElecStationId());
        if (list == null || list.size() < 1) {
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
        StringBuffer sb = new StringBuffer();

        Iterator<ElecStationPrice> iterator = list.iterator();
        if (priceType.equals(SocketConstant.STR_CON1)) {
            while (iterator.hasNext()) {
                ElecStationPrice next = iterator.next();
                sb.append(sdf.format(next.getBeginTime())).append("~")
                        .append(sdf.format(next.getEndTime())).append(" ")
                        .append(next.getElecPrice()).append("元/度")
                        .append("#");
            }
        } else {
            while (iterator.hasNext()) {
                ElecStationPrice next = iterator.next();
                sb.append(sdf.format(next.getBeginTime())).append("~")
                        .append(sdf.format(next.getEndTime())).append(" ")
                        .append(next.getServicePrice()).append("元/度")
                        .append("#");
            }
        }

        return sb.toString().substring(0, sb.length() - 1);
    }

}
